package com.zut.dao;

import com.zut.domain.EnvData;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EnvDataDao {

    @Insert("insert into env_data(temperature,humidity,distance,timestamp,token) " +
            "values (#{temperature},#{humidity},#{distance},#{timestamp},#{token})" )
    int insert(EnvData envData) ;


    @Select("SELECT DATE(timestamp) AS timestamp, AVG(temperature) AS temperature, AVG(humidity) AS humidity, AVG(distance) AS distance " +
            "FROM env_data " +
            "WHERE DATE(timestamp) BETWEEN #{startTimestamp} AND #{endTimestamp} AND token = #{token} " +
            "GROUP BY DATE(timestamp)" +
            "ORDER BY DATE(timestamp) DESC")
    List<EnvData> selectByTimestampIntervalAndToken(String startTimestamp, String endTimestamp, String token);
}
